<!DOCTYPE html>
<html lang="en" xmlns:th="https://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <title>
        后台管理系统
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" th:href="@{/assets/admin/css/font.css}">
    <link rel="stylesheet" th:href="@{/assets/admin/css/xadmin.css}">
    <script th:src="@{/assets/admin/lib/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/assets/admin/js/xadmin.js}"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="parentId" class="layui-form-label">
                <span class="x-red">*</span>所在目录名
            </label>
            <div class="layui-input-inline">
                <select id="parentId" name="parentId">
                    <option value="">请选择所在目录</option>
                    <option th:each="menu:${menus}" th:value="${menu.id}" th:text="${menu.menuname}"></option>
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>所属父菜单，如果作为一级父菜单，不用选择
            </div>
        </div>
        <div class="layui-form-item">
            <label for="menuname" class="layui-form-label">
                <span class="x-red"></span>菜单名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="menuname" name="menuname" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="menuCode" class="layui-form-label">
                <span class="x-red">*</span>菜单编号
            </label>
            <div class="layui-input-inline">
                <input type="text" id="menuCode" name="menuCode" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>唯一标识
            </div>
        </div>
        <div class="layui-form-item">
            <label for="sortNo" class="layui-form-label">
                <span class="x-red">*</span>排序
            </label>
            <div class="layui-input-inline">
                <input type="text" id="sortNo" name="sortNo" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="url" class="layui-form-label">
                <span class="x-red">*</span>请求路径
            </label>
            <div class="layui-input-inline">
                <input type="text" id="url" name="url" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>不包含中文与特殊字符
            </div>
        </div>
        <div class="layui-form-item">
            <label for="" class="layui-form-label">
            </label>
            <button class="layui-btn" lay-filter="add" lay-submit="">
                增加
            </button>
        </div>
    </form>
</div>
<script>
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        form = layui.form;
        layer = layui.layer;

        //监听提交
        form.on('submit(add)', function (data) {
            //console.log(typeof data.field);
            var status = data.field.status;
            if("on" == status){
                data.field.status = 1;
            }else{
                data.field.status = 0;
            }
            //console.log(data);
            //发异步，把数据提交给后台处理
            $.ajax({
                url: "/system/addMenu",
                data: JSON.stringify(data.field),
                type: "post",
                dataType: "json",
                contentType: "application/json;charset=utf-8",
                success: function (data) {
                    //console.log(data.message);
                    if (data.code == 200) {
                        layer.alert(data.message, {icon: 6}, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                    } else {
                        layer.alert(data.message, {icon: 5}, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                    }
                }
            });
            return false;
        });
    });
</script>

</body>

</html>